//
//  XWTestCodeVC.m
//  XWSegmentedControlTest
//
//  Created by wzl on 2017/3/20.
//  Copyright © 2017年 亮哥. All rights reserved.
//

#import "XWTestCodeVC.h"
#import <XWSegmentedControl/XWSegmentedControl.h>

@interface XWTestCodeVC ()<XWSegmentedControlDelegate>
@property (nonatomic,strong) XWSegmentedControl *mySegmentCtrl;
@end

@implementation XWTestCodeVC
#pragma mark - 父类方法
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.mySegmentCtrl];
    self.title = @"手写代码加载测试";
    
    NSMutableArray  *views =[[NSMutableArray alloc] init];
    NSArray *titles = @[@"测试1",@"测试2",@"测试3",@"测试4"];
    for (int i = 0; i<4; i++) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.mySegmentCtrl.frame), [[UIScreen mainScreen] bounds].size.width, 300)];
        UILabel*label = [[UILabel alloc] initWithFrame:CGRectMake(30, 30, 100, 21)];
        label.text = [titles objectAtIndex:i];
        [view addSubview:label];
        [self.view addSubview:view];
        [views addObject:view];
    }
    
    [self.mySegmentCtrl setSegmentedControlTitles:titles andViews:views];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}

#pragma mark - 私有方法
-(XWSegmentedControl *)mySegmentCtrl{
    if (_mySegmentCtrl == nil) {
        _mySegmentCtrl = [[XWSegmentedControl alloc] initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, 40)];
        _mySegmentCtrl.delegate = (id)self;
        
    }
    
    return _mySegmentCtrl;
}

#pragma mark - XWSegmentedControlDelegate
- (void)segmentedControl:(XWSegmentedControl*)segmentedControl didSelectSegmentIndex:(NSInteger)segmentIndex{
    NSLog(@"选中的index=%li",segmentIndex);
}
@end
